home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-07-15 | 17.7 KB | 514 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UTwistDownElement.cp
- // ETO20 MacApp 3.3.1, MPW 3.4.1
- // Copyright ©1995-1996 Conrad Kopala
- // Twist Down Lists version 2.0a0 7/15/96
- //----------------------------------------------------------------------------------------
-
- #ifndef __UTWISTDOWNELEMENT__
- #include "UTwistDownElement.h"
- #endif
-
- #ifndef __UTWISTDOWNAPP__
- #include "UTwistDownApp.h"
- #endif
-
- #ifndef __UTWISTDOWNDOCUMENT__
- #include "UTwistDownDocument.h"
- #endif
- /*
- #ifndef __UTWISTDOWNVIEW__
- #include "UTwistDownView.h"
- #endif
- */
- #ifndef __UTWISTDOWNGLOBALS__
- #include "UTwistDownGlobals.h"
- #endif
-
- //MacApp stuff
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
-
- #ifndef __UDEBUG__
- #include "UDebug.h" //PPC
- #endif
-
- //ToolBox stuff
- #ifndef __AEREGISTRY__
- #include "AERegistry.h"
- #endif
-
- //ANSI stuff
- //None
- //========================================================================================
- // CLASS TTwistDownElement
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment AOpen
- MA_DEFINE_CLASS_M2(TTwistDownElement, Inherited, MScriptableObject);
-
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::TTwistDownElement
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- TTwistDownElement::TTwistDownElement(): MScriptableObject(cTwistDownElement)
- {
- fTwistDownDocument = NULL;
- fSuccessorElement = NULL;
- fDescendantElement = NULL;
- fItemInList = 0;
- fIndentLevel = 0;
- fHasSubList = FALSE;
- fShowSubList = FALSE;
- fOldShowSubList = FALSE;
- fDisplayedText = gEmptyString;
- fTwistDownControl = NULL;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::~TTwistDownElement
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
- TTwistDownElement::~TTwistDownElement()
- {
- fTwistDownDocument = NULL;
- fSuccessorElement = NULL;
- fDescendantElement = NULL;
- fDisplayedText = gEmptyString;
-
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::ITwistDownElement
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
- void TTwistDownElement::ITwistDownElement(TTwistDownDocument* twistDownDocument, short indentLevel,
- CStr63 displayedText)
- {
- this -> IObject();
- fTwistDownDocument = twistDownDocument;
- fIndentLevel = indentLevel;
- fHasSubList = FALSE;
- fShowSubList = FALSE;
- fOldShowSubList = FALSE;
- fDisplayedText = displayedText;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::GetDisplayedText
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownElement::GetDisplayedText(CStr63& theDisplayedText)
- {
- theDisplayedText = fDisplayedText;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::SetHasSubListFlag //is being used -s
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
- void TTwistDownElement::SetHasSubListFlag()
- {
- fHasSubList = TRUE;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::ClearHasSubListFlag Is never used. Included for completeness.
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownElement::ClearHasSubListFlag()
- {
- fHasSubList = FALSE;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::TestHasSubListFlag //is being used
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- Boolean TTwistDownElement::TestHasSubListFlag()
- {
- return fHasSubList;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::SetShowSubListFlag used by TTwistDownDocument::SetShowSubListFlags
- //----------------------------------------------------------------------------------------
- //Good programming practice: The calling methods should make sure it is appropriate to
- //call SetShowSubListFlag() before calling it. To enforce that practice, I've put in the
- //ProgramBreak.
-
- #pragma segment ARes
- void TTwistDownElement::SetShowSubListFlag()
- {
- if (this -> TestHasSubListFlag()) //Make sure it makes sense to set this flag. Defensive programming.
- {
- fOldShowSubList = fShowSubList;
- fShowSubList = TRUE;
- }
- #if qDebug
- else
- ProgramBreak("Attempted to set fShowSubList when fHasSubList == FALSE!");
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::ClearShowSubListFlag Used by TTwistDownDocument::ClearShowSubListFlags
- //----------------------------------------------------------------------------------------
- //Good programming practice: The calling methods should make sure it is appropriate to
- //call ClearShowSubListFlag() before calling it. To enforce that practice, I've put in the
- //ProgramBreak.
-
- #pragma segment ARes
- void TTwistDownElement::ClearShowSubListFlag()
- {
- if (this -> TestHasSubListFlag()) //Make sure it makes sense to clear this flag. //Defensive programming.
- {
- fOldShowSubList = fShowSubList; //maybe I should just set to FALSE??
- fShowSubList = FALSE;
- }
-
- #if qDebug
- else if (this -> TestHasSubListFlag() == FALSE)
- ProgramBreak("Attempted to clear fShowSubList when fHasSubList == FALSE!");
- else
- ProgramBreak("ClearShowSubListFlag- fHasSublist == TRUE");
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::RestoreShowSubListFlag used by TTwistDownDocument::RestoreShowSubListFlags
- //----------------------------------------------------------------------------------------
- //Good programming practice: The calling methods should make sure it is appropriate to
- //call ClearShowSubListFlag() before calling it. To enforce that practice, I've put in the
- //ProgramBreak.
-
- #pragma segment ARes
- void TTwistDownElement::RestoreShowSubListFlag()
- {
- if (this -> TestHasSubListFlag()) //Make sure it makes sense to clear this flag. //Defensive programming.
- {
- fShowSubList = fOldShowSubList;
- fOldShowSubList = FALSE;
- }
-
- #if qDebug
- else if (this -> TestHasSubListFlag() == FALSE)
- ProgramBreak("Attempted to clear fShowSubList when fHasSubList == FALSE!");
- else
- ProgramBreak("ClearShowSubListFlag- fHasSublist == TRUE");
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::TestShowSubListFlag //is being used
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- Boolean TTwistDownElement::TestShowSubListFlag()
- {
- return fShowSubList;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::SetOldShowSubListFlag //is being used
- //----------------------------------------------------------------------------------------
- //Good programming practice: The calling methods should make sure it is appropriate to
- //call SetShowSubListFlag() before calling it. To enforce that practice, I've put in the
- //ProgramBreak.
-
- #pragma segment ARes
- void TTwistDownElement::SetOldShowSubListFlag()
- {
- if (this -> TestHasSubListFlag()) //Make sure it makes sense to set this flag. Defensive programming.
- {
- fOldShowSubList = TRUE;
- }
- #if qDebug
- else
- ProgramBreak("Attempted to set fOldShowSubList when fHasSubList == FALSE!");
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::ClearOldShowSubListFlag //is being used
- //----------------------------------------------------------------------------------------
- //Good programming practice: The calling methods should make sure it is appropriate to
- //call ClearShowSubListFlag() before calling it. To enforce that practice, I've put in the
- //ProgramBreak.
-
- #pragma segment ARes
- void TTwistDownElement::ClearOldShowSubListFlag()
- {
- if (this -> TestHasSubListFlag()) //Make sure it makes sense to clear this flag. //Defensive programming.
- {
- fOldShowSubList = FALSE;
- }
-
- #if qDebug
- else if (this -> TestHasSubListFlag() == FALSE)
- ProgramBreak("Attempted to clear fOldShowSubList when fHasSubList == FALSE!");
- else
- ProgramBreak("ClearOldShowSubListFlag- fHasSublist == TRUE");
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::TestOldShowSubListFlag //is being used
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- Boolean TTwistDownElement::TestOldShowSubListFlag()
- {
- return fOldShowSubList;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::SetSuccessorElementTo
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
- void TTwistDownElement::SetSuccessorElementTo(TTwistDownElement* theSuccessorElement)
- {
- fSuccessorElement = theSuccessorElement;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::SetDescendantElementTo
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
- void TTwistDownElement::SetDescendantElementTo(TTwistDownElement* theDescendantElement)
- {
- fDescendantElement = theDescendantElement;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::GetSuccessorElement
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TTwistDownElement* TTwistDownElement::GetSuccessorElement()
- {
- return fSuccessorElement;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::GetDescendantElement
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TTwistDownElement* TTwistDownElement::GetDescendantElement()
- {
- return fDescendantElement;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::SetTwistDownControlTo
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownElement::SetTwistDownControlTo(TTwistDownControl* theTwistDownControl)
- {
- fTwistDownControl = theTwistDownControl;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::GetTwistDownControl
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TTwistDownControl* TTwistDownElement::GetTwistDownControl()
- {
- return fTwistDownControl;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::SetIndentLevel is not being used, included for completeness.
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
- void TTwistDownElement::SetIndentLevel(short indentLevel)
- {
- fIndentLevel = indentLevel;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::GetIndentLevel //is being used
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- short TTwistDownElement::GetIndentLevel()
- {
- return fIndentLevel;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::SetItemInList -s
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
- void TTwistDownElement::SetItemInList(long itemInList)
- {
- fItemInList = itemInList;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::GetItemInList
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- long TTwistDownElement::GetItemInList()
- {
- return fItemInList;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::CouldExpandElement
- //Tests to make sure the capacity of TTwistDownView (TTextListView) will not be exceeded by an
- //attempt to expand the element.
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- Boolean TTwistDownElement::CouldExpandElement()
- {
- Boolean result = FALSE;
- long newNumberOfRows = 0;
-
- this -> SetShowSubListFlag();
- newNumberOfRows = fTwistDownDocument -> CountVisibleElements(fTwistDownDocument -> GetHeadOfList());
-
- if (newNumberOfRows <= (long)kMaxNumberOfItemsToDisplay)
- result = TRUE;
-
- this -> ClearShowSubListFlag();
-
- return result;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::DoScriptCommand: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- void TTwistDownElement::DoScriptCommand(CommandNumber aCommandNumber, TAppleEvent* message, TAppleEvent* reply)
- {
- switch (aCommandNumber)
- {
- case cExpandElement:
- {
- if (this -> TestHasSubListFlag()) //Make sure it is a folder.
- {
- if (!this -> TestShowSubListFlag()) //Make sure it isn't already expanded.
- {
- if (this -> CouldExpandElement()) //Make sure we won't exceed max number of rows.
- {
- TExpandElementCommand* anExpandElementCommand = new TExpandElementCommand;
- anExpandElementCommand -> IExpandElementCommand(fTwistDownDocument, this,
- message -> fMessage, reply -> fMessage);
- fTwistDownDocument -> PostCommand(anExpandElementCommand);
- }
- else
- FailOSErr(errCantExpandElement);
- }
- else
- FailOSErr(errElementAlreadyExpanded);
- }
- else
- FailOSErr(errAENotAFolder);
- }
- break;
-
- case cCollapseElement:
- {
- if (this -> TestHasSubListFlag()) //Make sure it is a folder.
- {
- if (this -> TestShowSubListFlag()) //Make sure it isn't already collpsed.
- {
- //Because we don't want this to fail for out of memory reasons,
- //allocate it from temporary memory. //PGMacApp 550
- //Note that TCollapseElementCommand may recover memory used by
- //TTwistDownControls.
- Boolean oldTemp = TemporaryAllocation(TRUE);
- Boolean oldArrayPerm = AllocateObjectsFromPerm(FALSE);
- TCollapseElementCommand* aCollapseElementCommand = new TCollapseElementCommand;
- aCollapseElementCommand -> ICollapseElementCommand(fTwistDownDocument, this,
- message -> fMessage, reply -> fMessage);
-
- fTwistDownDocument -> PostCommand(aCollapseElementCommand);
- oldArrayPerm = AllocateObjectsFromPerm(oldArrayPerm);
- oldTemp = TemporaryAllocation(oldTemp);
- }
- else
- FailOSErr(errElementAlreadyCollapsed);
-
- }
- else
- FailOSErr(errAENotAFolder);
- }
- break;
-
- default:
- {
- MScriptableObject::DoScriptCommand(aCommandNumber, message, reply);
- }
- break;
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::GetSpecifierForm: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- DescType TTwistDownElement::GetSpecifierForm()
- {
- return formName;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::GetObjectProperty: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- Boolean TTwistDownElement::GetObjectProperty(CAEDesc& thePropertyValue,
- DescType whichProperty,
- const CAEDesc& desiredType)
- {
-
- Boolean hasProperty = TRUE;
-
- FailInfo fi;
- Try(fi)
- {
- switch (whichProperty)
- {
-
- case pName:
- CStr255 theName;
- theName = fDisplayedText;
- thePropertyValue.PutString(theName);
- break;
-
- case pHasSubList:
- thePropertyValue.PutBoolean(fHasSubList);
- break;
-
- case pShowSubList:
- thePropertyValue.PutBoolean(fShowSubList);
- break;
-
- case pHasControl:
- {
- Boolean hasControl = FALSE;
- if (fTwistDownControl)
- hasControl = TRUE;
- thePropertyValue.PutBoolean(hasControl);
- }
- break;
-
- case pItemInList:
- thePropertyValue.PutLong(fItemInList);
- break;
-
- case pIndentLevel:
- long itsIndentLevel = (long)fIndentLevel;
- thePropertyValue.PutLong(itsIndentLevel);
- break;
-
- default:
- hasProperty = MScriptableObject::GetObjectProperty(thePropertyValue, whichProperty, desiredType);
- break;
- }
- fi.Success();
- }
- else
- {
- // we failed while trying to get the property
- hasProperty = FALSE;
-
- // Don't ReSignal
- }
- return hasProperty;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownElement::GetObjectsContainer
- //----------------------------------------------------------------------------------------
- #pragma segment MAOSLDispatch
- MScriptableObject* TTwistDownElement::GetObjectsContainer()
- {
- return (MScriptableObject*)fTwistDownDocument;
- }
-
- #pragma segment Inline